﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using Meqs.Logic.Interface;
using System.Collections.Generic;

public partial class Moral_Teacher_RuleSettings_SettingEvalDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Repeater1.DataSource = GetEvalList();
            Repeater1.DataBind();
        }
    }


    /// <summary>
    /// 获取当前学年学期的带有课程名的学分记录
    /// </summary>
    /// <returns></returns>
    private IList<MoralityHistoryView> GetEvalList()
    {
        IList<MoralityHistoryView> mhvs = new List<MoralityHistoryView>();
        SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
        int schoolYear = si.SchoolYear;
        int term = si.SchoolTerm;
        string schoolMark = si.SchoolMark;

        IMoralityHistoryLogic logic = Container<IMoralityHistoryLogic>.Instance;


        Hashtable ht = new Hashtable();
        ht.Add("SchoolYear", schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", MoralityHistory.SystemSiteName);
        IList<MoralityHistory> list = logic.FindAll(ht);
        foreach (MoralityHistory cl in list)
        {
            MoralityHistoryView mhv = new MoralityHistoryView();
            mhv.EvalType = 1;
            mhv.Attribute = cl.Attribute;
            mhv.Caption = cl.Caption;
            mhv.KeyWord = cl.KeyWord;
            mhv.ManagerID = cl.ManagerID;
            mhv.RID = cl.RID;
            mhv.SchoolMark = cl.SchoolMark;
            mhv.SchoolYear = cl.SchoolYear;
            mhv.Site = cl.Site;
            mhv.Status = cl.Status;
            mhv.Term = cl.Term;
            mhvs.Add(mhv);
        }

        IClassEvalHistoryLogic logic1 = Container<IClassEvalHistoryLogic>.Instance;

        ht = new Hashtable();
        ht.Add("SchoolYear", schoolYear);
        ht.Add("Term", term);
        ht.Add("SchoolMark", si.SchoolMark);
        ht.Add("Site", MoralityHistory.SystemSiteName);
        IList<ClassEvalHistory> list2 = logic1.FindAll(ht);

        foreach(ClassEvalHistory cl in list2)
        {
            MoralityHistoryView mhv = new MoralityHistoryView();
            mhv.EvalType = 2;
            mhv.Attribute = cl.Attribute;
            mhv.Caption = cl.Caption;
            mhv.KeyWord = cl.KeyWord;
            mhv.ManagerID = cl.ManagerID;
            mhv.RID = cl.RID;
            mhv.SchoolMark = cl.SchoolMark;
            mhv.SchoolYear = cl.SchoolYear;
            mhv.Site = cl.Site;
            mhv.Status = cl.Status;
            mhv.Term = cl.Term;
            mhvs.Add(mhv);
        }
        return mhvs;
    }

    /// <summary>
    /// 验证当前是否是新学年学期
    /// </summary>
    /// <returns></returns>
    private bool ValidateIsNewTerm()
    {
        int schoolYear = SchoolCommon.Sch_SchoolInfo.SchoolYear;
        int term = SchoolCommon.Sch_SchoolInfo.SchoolTerm;

        IStuCauseEvalHistoryLogic logic = Container<IStuCauseEvalHistoryLogic>.Instance;
        Hashtable table = new Hashtable();
        table.Add("SchoolMark", Common.GetConstSchoolMark());
        table.Add("SchoolYear", SchoolCommon.Sch_SchoolInfo.SchoolYear);
        table.Add("Term", SchoolCommon.Sch_SchoolInfo.SchoolTerm);

        List<StuCauseEvalHistory> list = (List<StuCauseEvalHistory>)logic.FindAll(table);

        if (list.Count > 0)
            return true;
        else
            return false;

    }

    [System.Web.Services.WebMethod]
    public static int SaveSure(int[] ids,int [] types)
    {
        for (int i = 0; i < types.Length;i++ )
        {
            if (types[i] == 1)
            {
                IMoralityHistoryLogic logic = Container<IMoralityHistoryLogic>.Instance;
                logic.UpdateStatus(Common.GetConstSchoolMark(), ids[i],1);
            }
            if (types[i] == 2)
            {
                IClassEvalHistoryLogic logic = Container<IClassEvalHistoryLogic>.Instance;
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", Common.GetConstSchoolMark());
                ht.Add("RID",ids[i]);
                ht.Add("Status", 1);
                logic.UpdateStatus(ht);
            }
        }


        return 1;
    }

    protected void btnBind_Click1(object sender, EventArgs e)
    {
        Repeater1.DataSource = GetEvalList();
        Repeater1.DataBind();
    }
}
//[Serializable]   已转移到MoralityHistory实体界面中
//public class MoralityHistoryView : MoralityHistory
//{
    
//    private int m_EvalType = -1;
//    /// <summary>
//    /// 评价类别 1:评学生 2:评班级
//    /// </summary>
//    public int EvalType
//    {
//        get { return m_EvalType; }
//        set { m_EvalType = value; }
//    }
//}